package Day14;

public class Demo03 {
    public static void main(String[] args) {
        //面向对象创建一个链表
        Node n = new Node("头结点");
        Node n1 = new Node("小李");
        Node n2 = new Node("多多");
        Node n3 = new Node("呆");
        n.setNext(n1);//该next储存下一个节点  以此类推
        n1.setNext(n2);
        n2.setNext(n3);
        n3.setNext(null);
        printAll(n);//遍历输出


        //

    }
    static void printAll(Node next){
        if(next == null){//判断书否为空  为空表示遍历结束
            return;
        }else{
            System.out.print(next.getName() + " ");
        }
        printAll(next.getNext());//递归继续调用
    }
}
class Node{//设置一个类
    private String name;//存储一个数据
    private Node next;//设置一个节点

    public Node() {
    }

    public Node(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Node getNext() {
        return next;
    }

    public void setNext(Node next) {
        this.next = next;
    }
}
